package com.hack4jp.hackearthquakes;

import java.io.File;
import java.io.FileOutputStream;
import android.os.Environment;

public class FileManager {
	
	public final static String
		APP_FOLDER_NAME = "Gaketter",
		IMAGES_FOLDER_NAME = "images",
   		TEMP_IMAGE_FILE_NAME ="temp.jpg";
	
	public static String getAppDirPath() {
		File f = new File(Environment.getExternalStorageDirectory(), APP_FOLDER_NAME);
		if (!f.exists()) {
			f.mkdir();
		}
		String appDirPath = f.getPath();
		return appDirPath;
	}
	
	public static String getImagesDirPath() {
		File f = new File(getAppDirPath(), IMAGES_FOLDER_NAME);
		if (!f.exists()) {
			f.mkdir();
		}
		String imagesDirPath = f.getPath();
		return imagesDirPath;		
	}
	
	public static String getTempImagePath() {
		String filePath = new File(getImagesDirPath(), TEMP_IMAGE_FILE_NAME).getPath();
		return filePath;
	}
	
	public static void saveFile(byte[] data,String fileName) throws Exception {
		FileOutputStream out = null;
		
		try {
			out = new FileOutputStream(fileName);
			out.write(data);
			out.close();
		} catch (Exception e) {
			if (out != null)
				out.close();
			
			throw e;
		} 
	}
}
